package com.keda.controller;

import com.keda.model.PageInfo;
import com.keda.model.Product;
import com.keda.service.ProductService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 商品搜索
 */
@WebServlet("/search")
public class ProductSearchServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        // 1. 接收查询参数
        String bigTypeId = request.getParameter("bigTypeId");
        String smallTypeId = request.getParameter("smallTypeId");
        String keyword = request.getParameter("keyword");
        request.setAttribute("bigTypeId", bigTypeId);
        request.setAttribute("smallTypeId", smallTypeId);
        request.setAttribute("keyword", keyword);

        // 接收分页参数
        // 页码
        String page = request.getParameter("page");

        ProductService productService = new ProductService();
        PageInfo<Product> pageInfo = productService.search(bigTypeId, smallTypeId, keyword, page);
        request.setAttribute("pageInfo", pageInfo);
        request.getRequestDispatcher("product.jsp").forward(request, response);
    }
}
